package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.CollectionGiftLog;
import com.sc.nft.entity.UserInfo;
import com.sc.nft.entity.vo.CollectionTransferSimpleListVO;
import com.sc.nft.entity.vo.PropTransferDetailsVO;
import com.sc.nft.entity.vo.PropTransferSimpleListVO;
import com.sc.nft.mapper.PropGiftLogMapper;
import com.sc.nft.entity.PropGiftLog;
import com.sc.nft.service.PropGiftLogService;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

/**
 * 权益道具赠送日志(PropGiftLog)表Dao层
 *
 * @author 王伟成
 * @since 2023-11-10 16:57:38
 */
@Slf4j
@Repository
public class PropGiftLogDao extends ServiceImpl<PropGiftLogMapper, PropGiftLog> {

    public IPage<PropTransferSimpleListVO> collectionTransferSimpleList(UserInfo userInfo, Page mp) {
        LambdaQueryWrapper<PropGiftLog> wrapper = Wrappers.lambdaQuery();
        wrapper.select(PropGiftLog::getPropId,PropGiftLog::getTitle,PropGiftLog::getCreateTime,PropGiftLog::getId);
        wrapper.eq(PropGiftLog::getGiftUserId,userInfo.getId());
        wrapper.orderByDesc(PropGiftLog::getId);
        Page<PropGiftLog> page = page(mp,wrapper);
        IPage<PropTransferSimpleListVO> result = page.convert(v -> {
            PropTransferSimpleListVO vo = new PropTransferSimpleListVO();
            vo.setId(v.getId());
            vo.setTitle(v.getTitle());
            vo.setCreateTime(v.getCreateTime());
            return vo;
        });
        return result;
    }
    public PropTransferDetailsVO getByIdDetails(Long id) {
        return baseMapper.getByIdDetails(id);
    }
}
